(function(){"use strict";BX.namespace("BX.Landing.UI.Form");BX.Landing.UI.Form.DynamicBlockForm=function(e){BX.Landing.UI.Form.BaseForm.apply(this,arguments);this.type=e.type;this.forms=e.forms;this.code=e.code;this.onSourceChangeHandler=e.onSourceChange;this.dynamicParams=e.dynamicParams;this.settingFieldsSelectors=["source"];this.addField(this.createSourceField())};BX.Landing.UI.Form.DynamicBlockForm.prototype={constructor:BX.Landing.UI.Form.DynamicBlockForm,__proto__:BX.Landing.UI.Form.BaseForm.prototype,getSources:function(){return BX.Landing.Main.getInstance().options.sources},getSourceById:function(e){return this.getSources().find(function(t){return String(t.id)===String(e)})},getSourcesFieldItems:function(){return this.getSources().map(function(e){return{name:e.name,value:e.id}})},createSourceField:function(){var e="";if(BX.type.isPlainObject(this.dynamicParams)&&BX.type.isPlainObject(this.dynamicParams.wrapper)&&BX.type.isPlainObject(this.dynamicParams.wrapper.settings)&&BX.type.isString(this.dynamicParams.wrapper.settings.source)){e=this.dynamicParams.wrapper.settings.source}var t=this.getSourceById(e);if(!t){t=this.getSources()[0]}setTimeout(function(){this.onSourceChangeHandler.apply(this,[t])}.bind(this),0);return new BX.Landing.UI.Field.Dropdown({title:BX.Landing.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_TITLE"),selector:"source",content:e,items:this.getSourcesFieldItems(),onValueChange:function(e){this.onSourceChangeHandler.apply(this,[this.getSourceById(e.getValue())])}.bind(this)})},isReference:function(e){var t=this.getSources();if(BX.type.isArray(t)){return t.some(function(t){if(BX.type.isArray(t.references)){return t.references.some(function(t){return t.id===e})}return false})}return false},serialize:function(){return this.fields.reduce(function(e,t){var i=t.getValue();if(this.settingFieldsSelectors.includes(t.selector)){if(t.selector==="source"){e.source=i}e.settings[t.selector]=i}else if(i==="@hide"||BX.type.isPlainObject(i)&&i.id==="@hide"){e.references[t.selector]="@hide";if(BX.hasClass(t.layout,"landing-ui-field-dynamic-dropdown")){e.stubs[t.selector]=""}else if(BX.hasClass(t.layout,"landing-ui-field-dynamic-image")){e.stubs[t.selector]={id:-1,src:"",alt:""}}}else{if(this.isReference(i)||BX.type.isPlainObject(i)&&BX.type.isString(i.id)){if(this.isReference(i)){e.references[t.selector]={id:i}}else{e.references[t.selector]=i}}else{e.stubs[t.selector]=i}}return e}.bind(this),{settings:{},references:{},stubs:{}})}}})();
//# sourceMappingURL=dynamic_block_form.map.js